﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YemekteyizLib;
using YemekteyizLib.Bs;
using System.Threading;

public partial class sepetOnay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AdresleriDoldur();




         if (!IsPostBack)
        {
            if (Session["ilID"] != null)
            {
                string IlID = Session["ilID"].ToString();

                Il i = new Il();
                i.ID = Convert.ToInt32(IlID);

                drpIlce.DataTextField = "Adi";
                drpIlce.DataValueField = "ID";
                List<Ilce> ilceler = IlceProvider.getByIl(i);
                ilceler.Sort();
                drpIlce.DataSource = ilceler;

                if (Request.QueryString["ilceID"] != null)
                {
                    drpIlce.SelectedValue = Request.QueryString["ilceID"];
                }
                DataBind();

            }
    }
  }
    private void AdresleriDoldur()
    {
        
        Uye u = Session["uye"] as Uye;

        if (u == null)
        {
            Response.Redirect("giris.aspx");   
        }

       DataList2.DataSource=UyeAdresProvider.GetAdreslerByUye(u);
        DataList2.DataBind();

        
    }

    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "AdresSec")
        {
            DataList2.SelectedIndex = e.Item.ItemIndex;
            AdresleriDoldur();
        }
    }
    protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void btnEkle_Click(object sender, EventArgs e)
    {
        UyeAdres u = new UyeAdres();
      
        u.Adresi = txtAdres.Text;
        u.Ilcesi = IlceProvider.GetByID(Convert.ToInt32(drpIlce.SelectedValue));
        u.Tarifi = txtTarif.Text;
        u.Telefonu = txtTelefon.Text;
        u.Sahibi = Session["uye"] as Uye;

         UyeAdresProvider.EkleAdres(u);



    }
    void MailGonderici()
    {
        MailGonder m = new MailGonder();
        Uye u = Session["uye"] as Uye;
        m.KullaniciyaMailGonder(u.AktifSepet);
        m.RestoranaMailGonder(u.AktifSepet, "nakit");
    }

    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        Thread t = new Thread(new ThreadStart(MailGonderici));
        t.Start();

        Uye u = Session["uye"] as Uye;

        u.AktifSepet.OnaylandiMi = true;
        SepetProvider.SepetOnayDegisti(u.AktifSepet);
        Response.Redirect("siparisOK.aspx");


    }
}
